<?php
// 身份审核
namespace app\api\controller;
use app\admin\model\SystemIdentity;
use app\admin\model\SystemUserApplication;
use think\facade\Config;

class Auditing extends LoginController
{

    public function test(){
        print_r(Config::get('app')['const_data']);
        exit;
    }

    /**
     * @identity_list   身份_列表
     */
    public function identity_list(){
        $identityModel = new SystemIdentity;
        
        $whereis = [];
        $count = $identityModel
            ->where($whereis)
            ->count();
        $list = $identityModel
            ->where($whereis)
            ->select();
        // 如果list为空 返回自定义报错
        if (!$list) {
            $result = [
                'code'  => -1,
                'msg'   => '身份列表暂无数据!',
            ];
        } else {
            $result = [
                'code'  => 1,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
        }
        
        return json($result);
    }

    /**
     * @product_recovery_add   成品库_添加回收
     * @param                  接口参数
     * @param.product_name     产品名称
     * @param.product_spec_id  规格ID
     * @param.product_sku      编号
     * @param.remark           备注
     */
    public function auditing_add(){
        $data = $this->request->param();

        if (empty($data['user_id'])) {
            return json([
                'code'  => -1,
                'msg'   => '缺少用户ID!',
            ]);
        }
        if (empty($data['identity_id'])) {
            return json([
                'code'  => -1,
                'msg'   => '缺少申请身份ID!',
            ]);
        }
        if (empty($data['user_name'])) {
            return json([
                'code'  => -1,
                'msg'   => '缺少用户姓名!',
            ]);
        }
        if (empty($data['company_name'])) {
            return json([
                'code'  => -1,
                'msg'   => '缺少公司名称!',
            ]);
        }
        if (empty($data['company_address'])) {
            return json([
                'code'  => -1,
                'msg'   => '缺少公司地址!',
            ]);
        }

        $arr['identity_id'] = $data['identity_id'];   //申请身份ID
        $arr['user_id'] = $data['user_id'];   //用户ID
        $arr['user_name'] = $data['user_name']; //用户姓名
        $arr['company_name'] = $data['company_name']; //公司名称
        $arr['company_address'] = $data['company_address']; //公司地址
        $arr['create_time'] = time(); //创建时间

        $auditingModel = new SystemUserApplication;
        try {
            $auditingModel->save($arr);
            $result = [
                'code'  => 1,
                'msg'   => '用户审核添加成功!',
            ];
        } catch (\Exception $e) {
            $result = [
                'code'  => -1,
                'msg'   => '用户审核添加失败!',
            ];
        }

        return json($result);
    }

}